﻿
/****** Object:  User Defined Function dbo.FiscalMonth    Script Date: 10/14/2009 10:39:06 PM ******/

CREATE FUNCTION [dbo].[FiscalMonth] (@FiscalWeek int)   
RETURNS int AS
BEGIN 

declare @FiscalMonthNumber int

if (@FiscalWeek between 1 and 5) set @FiscalMonthNumber = 1
else if (@FiscalWeek between 6 and 9) set @FiscalMonthNumber = 2
else if (@FiscalWeek between 10 and 13) set @FiscalMonthNumber = 3
else if (@FiscalWeek between 14 and 18) set @FiscalMonthNumber = 4
else if (@FiscalWeek between 19 and 22) set @FiscalMonthNumber = 5
else if (@FiscalWeek between 23 and 26) set @FiscalMonthNumber = 6
else if (@FiscalWeek between 27 and 31) set @FiscalMonthNumber = 7
else if (@FiscalWeek between 32 and 35) set @FiscalMonthNumber = 8
else if (@FiscalWeek between 36 and 39) set @FiscalMonthNumber = 9
else if (@FiscalWeek between 40 and 44) set @FiscalMonthNumber = 10
else if (@FiscalWeek between 45 and 48) set @FiscalMonthNumber = 11
else if (@FiscalWeek between 49 and 53) set @FiscalMonthNumber = 12
return @FiscalMonthNumber
END




